package backstage.competence.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import backstage.competence.dao.CompetenceDao;
import backstage.competence.pojo.Competence;
import backstage.sys.dao.SystemDao;
import backstage.util.pojo.Page;

public class CompetenceDaoImpl extends SystemDao implements CompetenceDao {


	public Competence getCompetence(Integer id) {
		List<Competence> list = getHibernateTemplate().find("from Competence where id=?",id);
		if(list != null){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	//增加
	public void seva(Competence c) {
		getHibernateTemplate().save(c);
	}

	//修改
	public void update(Competence c) {
		getHibernateTemplate().update(c);
	}
	
	//删除
	public void delete(Competence c) {
		getHibernateTemplate().delete(c);
	}
	
	//分页
	public Page getPage(int pageSize){
		Page p = this.getPageCount("select count(*) from Competence", pageSize);
		return p;
	}

	//根据分页查询
	public List<Competence> getCompetenceList(String hql, Page pager) {
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Query query = session.createQuery(hql);
		query.setFirstResult((pager.getCurPage() - 1) * pager.getPageSize());
		query.setMaxResults(pager.getPageSize());
		List<Competence> list = query.list();
		session.close();
		return list;
	}

}
